package com.oocl.service.impl;

import java.util.List;

import com.oocl.dao.CustomerDao;
import com.oocl.dao.FavcDao;
import com.oocl.dao.impl.CustomerDaoImpl;
import com.oocl.dao.impl.FavcDaoImpl;
import com.oocl.pojo.Customer;
import com.oocl.service.CustomerService;

public class CustomerServiceImpl   implements CustomerService{
	 
	 private CustomerDao customerDao;
	 private FavcDao fDao;
	 
	 public CustomerServiceImpl(){
		 this.fDao =new FavcDaoImpl();
		 this.customerDao = new CustomerDaoImpl();
	 }

	

	public List<Customer> getList() {
		// TODO Auto-generated method stub
		return customerDao.findAll();
	}

	public boolean addCustomer(Customer c, int[] favcIds) {
		int count  = customerDao.insertOne(c,favcIds);
		
		if(count==1) return true;
		return false;
	}



	public Customer loadCustomer(Integer id) {
		// TODO Auto-generated method stub
		return customerDao.load(id);
	}



	public boolean update(Customer c, int[] favcIds) {
		customerDao.update(c);
		
		if(favcIds.length!=0){
				 fDao.remove(c.getId());
			for(int i=0;i<favcIds.length;i++){
				fDao.insertOne(c.getId(),favcIds[i]);
			}
		}
		return true;
	}



	public boolean remove(int id) {
		int count = 0;
		int count1 = 0;
		count1 = fDao.remove(id);
		count = customerDao.delete(id);
		if(count>0&&count1>=0) return true;
		return false;
	}

}
